package com.pro.controller;



import com.pro.pojo.JsDept;
import com.pro.pojo.JsDeptAuthority;
import com.pro.pojo.JsonData;
import com.pro.service.JsDeptManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:JsDeptManagementController
 * Package:com.pro.controller
 * Description: 部门管理Controller
 *
 * @Date:2022/2/8 上午 9:04
 * @Author: WYH
 */
@RestController
@RequestMapping("/deptManagement")
public class JsDeptManagementController {

    @Autowired
    private JsDeptManagementService jsDeptManagementService;

    /**
     * @Author WYH
     * @Description //TODO 查看所有部门信息
     * @Date 上午 9:06 2022/2/8
     * @Param deptName,trueName,createDate,status,limit,page
     * @return  JsonData
     **/
    @RequestMapping("/getJsDeptList")
    public JsonData getJsDeptList(String deptName, String trueName, String createDate, String status, Integer limit, Integer page){
        deptName = deptName != null  ? "%"+deptName+"%":"%%";
        trueName = trueName != null  ? "%"+trueName+"%":"%%";
        createDate = createDate != null  ? "%"+createDate+"%":"%%";
        status = status != null  ? "%"+status+"%":"%%";
        List<JsDept> jsDeptList = jsDeptManagementService.getJsDeptList(deptName, trueName, createDate, status, limit, page);
        Integer integer = jsDeptManagementService.countJsDeptList(deptName, trueName, createDate, status);
        return jsDeptList != null ? JsonData.buildSuccess(jsDeptList,integer) : JsonData.buildError("数据格式异常");
    }

    /**
     * @Author WYH
     * @Description //TODO 修改状态
     * @Date 上午 9:37 2022/2/9
     * @Param jsDept
     * @return  JsonData
     **/
    @RequestMapping("/updateStatus")
    public JsonData updateStatus(JsDept jsDept){
        Boolean updateStatus = jsDeptManagementService.updateStatus(jsDept);
        return updateStatus != false ? JsonData.buildSuccess(updateStatus) : JsonData.buildError("数据格式异常");
    }

    /**
     * @Author WYH
     * @Description //TODO 删除部门
     * @Date 上午 10:02 2022/2/9
     * @Param id
     * @return  JsonData
     **/
    @RequestMapping("/deleteDept")
    public JsonData deleteDept(Integer id){
        Boolean deleteDept = jsDeptManagementService.deleteDept(id);
        return deleteDept != false ? JsonData.buildSuccess(deleteDept) : JsonData.buildError("数据格式异常");
    }

    /**
     * @Author WYH
     * @Description //TODO 根据id查询部门
     * @Date 上午 10:35 2022/2/9
     * @Param id
     * @return JsDept
     **/
    @RequestMapping("/getJsDeptById")
    public JsonData getJsDeptById(Integer id){
        JsDept jsDeptById = jsDeptManagementService.getJsDeptById(id);
        return jsDeptById != null ? JsonData.buildSuccess(jsDeptById) : JsonData.buildError("数据格式异常");
    }

    /**
     * @Author WYH
     * @Description //TODO 编辑部门
     * @Date 上午 10:45 2022/2/9
     * @Param jsDept
     * @return  true | false
     **/
    @RequestMapping("/updateJsDept")
    public JsonData updateJsDept(JsDept jsDept){
        Boolean updateJsDept = jsDeptManagementService.updateJsDept(jsDept);
        return updateJsDept != false ? JsonData.buildSuccess(updateJsDept) : JsonData.buildError("数据格式异常");
    }

    /**
     * @Author WYH
     * @Description //TODO 添加部门
     * @Date 下午 10:28 2022/2/10
     * @Param jsDept
     * @return  JsonData
     **/
    @RequestMapping("/addJsDeptList")
    public JsonData addJsDeptList(JsDept jsDept){
        Boolean addJsDeptList = jsDeptManagementService.addJsDeptList(jsDept);
        Boolean addJsDeptAuthority = jsDeptManagementService.addJsDeptAuthority(new JsDeptAuthority(jsDept.getId(), jsDept.getDeptDescirbe()));
        Boolean look = false;
        if(addJsDeptList&&addJsDeptAuthority!=null){
            look = true;
        }
        return look!=false? JsonData.buildSuccess(look): JsonData.buildError("服务端错误");
    };
}



